package cn.wyz.basic.service.impl;

import cn.wyz.basic.mapper.BaseMapper;
import cn.wyz.basic.query.BaseQuery;
import cn.wyz.basic.service.IBaseService;
import cn.wyz.basic.util.PlusQueryList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public List<T> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public T selectById(Long id) {
        return mapper.selectById(id);
    }

    @Override
    @Transactional
    public void deleteById(Long id) {
        mapper.deleteById(id);
    }

    @Override
    @Transactional
    public void insert(T t) {
        mapper.insert(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public PlusQueryList<T> queryData(BaseQuery query) {
        Long total = mapper.queryCount(query);
        List<T> rows = mapper.queryData(query);
        return new PlusQueryList<T>(total,rows);
    }

    @Override
    @Transactional
    public void patchDelete(List<Long> idList) {
        mapper.patchDel(idList);
    }
}
